package cdp.tarasenko.epamevospring.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Arrays;
import java.util.List;

/**
 * @author Oleksandr_Tarasenko
 */
@Document(collection = "evodata")
public class QuarterEvoData {

    @Id
    private int id;
    private int quarter;
    private int year;
    private List<CityEvoData> cities;

    public QuarterEvoData(){}

    public QuarterEvoData(int id, int quarter, int year, List<CityEvoData> cities) {
        this.id = id;
        this.quarter = quarter;
        this.year = year;
        this.cities = cities;
    }

    public QuarterEvoData(int quarter, int year, List<CityEvoData> cities) {
        this.quarter = quarter;
        this.year = year;
        this.cities = cities;
    }

    public int  getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getQuarter() {
        return quarter;
    }

    public void setQuarter(int quarter) {
        this.quarter = quarter;
    }

    public List<CityEvoData> getCities() {
        return cities;
    }

    public void setCities(List<CityEvoData> cities) {
        this.cities = cities;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        QuarterEvoData that = (QuarterEvoData) o;

        if (quarter != that.quarter) return false;
        if (!cities.equals(that.cities)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = quarter;
        result = 31 * result + cities.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "{" +
                "quarter:" + quarter +
                ", cities:" + Arrays.toString(cities.toArray()) +
                "}";
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public static class CityEvoData {

        private String city;
        private int employees;

        public String getCity() {
            return city;
        }

        public int getEmployees() {
            return employees;
        }

        public CityEvoData(String city, int employees) {
            this.city = city;
            this.employees = employees;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            CityEvoData that = (CityEvoData) o;

            if (employees != that.employees) return false;
            if (!city.equals(that.city)) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = city.hashCode();
            result = 31 * result + employees;
            return result;
        }

        @Override
        public String toString() {
            return "{" +
                    "city:'" + city + '\'' +
                    ", employees:" + employees +
                    '}';
        }
    }
}
